package com.xxz.terminal;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {

    private static final int VERSION = 1;
    private static final String DB_NAME = "my.db";
    public static final String TB1_NAME = "userinformation";
    public static final String TB2_NAME = "diary_data";
    public static final String TB3_NAME = "sentence_data";
    public static final String TB4_NAME = "treehole_diary_likestore";
//    public static final String TB5_NAME = "treehole_sentence_likestore";
    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                    int version) {
        super(context, name, factory, version);
    }
    public DBHelper(Context context) {
        super(context,DB_NAME,null,VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i("TAG", "onCreate: " );

        db.execSQL("PRAGMA foreign_keys=ON;");
        db.execSQL("CREATE TABLE "+TB1_NAME+"(user_id TEXT PRIMARY KEY ,password TEXT,nickname TEXT,motto TEXT)");//用户信息表
        db.execSQL("CREATE TABLE "+TB2_NAME+"(user_id TEXT FOREIGNKEY references userinformation(user_id) ,diarydata TEXT,date DATE," +
                "treehole_status TEXT,treehole_time TEXT)");//用户日记信息表
        db.execSQL("CREATE TABLE "+TB3_NAME+"(user_id TEXT FOREIGNKEY references userinformation(user_id)" +
                " ,sentence TEXT,source TEXT,review_text TEXT,date DATE,treehole_status TEXT)");//用户句子信息表
        db.execSQL("CREATE TABLE "+TB4_NAME+"(user_id TEXT FOREIGNKEY references userinformation(user_id) ,treehole_diarydata TEXT" +
                ",treehole_date DATE,store_date DATE,author_id TEXT)");//用户他人日记信息收藏表
//        db.execSQL("CREATE TABLE "+TB5_NAME+"(user_id TEXT FOREIGNKEY references userinformation(user_id)" +
//                " ,treehole_sentence TEXT,treehole_source TEXT,review_text TEXT,date DATE,author_name TEXT,author_id TEXT)");//用户他人句子信息收藏表
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
        // TODO Auto-generated method stub
    }

}